// 构造每一个医生的“框”
function createDoctor(img,title,content) {
	var element =	'<div class="doctorblock">' +
					'<div class="doctor">' +
					'<img src="'+img+'" width="194" height="350" alt=""/>' +
					'<div class="doctordoc">' +
					'<h3>'+title+'</h3>' +
					'<p>'+content+'</p>' +
					'<a href="#">了解更多</a>' +
					'</div>' +
					'<ul class="perinfo">' +
					'<li><span class="infoword">关注数</span><span class="infonum red">123</span></li>' +
					'<li><span class="infoword">被关注数</span><span class="infonum yellow">1024</span></li>' +
					'<li><span class="infoword">治愈患者</span><span class="infonum green">324</span></li>' +
					'</ul>' +
					'<div class="button"><a href="#" class="register">挂&nbsp;&nbsp;号</a></div>' +
					'</div>' +
					'</div>';
	return element;
}

$(document).ready(function(){
	// 滚动加载代码
	var winHeight = $(window).height();
	$(window).resize(function(){
		winHeight = $(window).height();// http://cued.xunlei.com/log031也许会参考改变窗口的延时做法
	});
	$(window).scroll(function(){// bug:scroll在不同的浏览器中触发次数不一，Chrome比较标准，就1次
		console.log(0);
		if($(document).scrollTop()+winHeight > $(document).height() - 100) {
			$.get('http://localhost:8080/Ajax/load',function(data){
				var doctors = JSON.parse(data);
				var numbers = doctors.ready.length;
				for(var i=0;i<numbers;i++){
					$('#column'+(i%4)).append(
						createDoctor(doctors.ready[i].head,doctors.ready[i].name,doctors.ready[i].resume)
					);
				}
			});
		}
	});
	// 下拉菜单
	$('#hospital, #department').hover(function(){
		$(this).next().show();
	}).parent().hover(function(){},function(){
		$(this).children('ul').hide();
	});
});